/// @tags: DP on Tree, ChangeRoot
#include <cstdio>
#include <iostream>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 2e5 + 1;

int n;
int ecnt;
int heads[maxn];

struct Edge {
  int v, nxt, w;
} e[maxn * 2];

inline void add(int u, int v, int w) {
  e[++ecnt].v = v, e[ecnt].w = w, e[ecnt].nxt = heads[u], heads[u] = ecnt;
}

int f[maxn][2], g[maxn], h[maxn][2];
int max1[maxn], max2[maxn], son1[maxn], son2[maxn], faw[maxn];

void dfs(int u, int fa) {
  max1[u] = max2[u] = -0x3fffffff;
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v != fa) {
      faw[v] = e[i].w;
      dfs(v, u);
      f[u][0] += std::max(f[v][0], f[v][1] + e[i].w);
      int val = f[v][0] + e[i].w - std::max(f[v][0], f[v][1] + e[i].w);
      if (val > max1[u])
        max2[u] = max1[u], max1[u] = val, son2[u] = son1[u], son1[u] = v;
      else if (val > max2[u])
        max2[u] = val, son2[u] = v;
    }
  }
  f[u][1] = f[u][0] + max1[u];
}

void changeRoot(int u, int fa) {
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v != fa) {
      h[u][0] = g[u] - std::max(f[v][0], f[v][1] + e[i].w);
      if (son1[u] == v) {
        std::swap(son1[u], son2[u]);
        std::swap(max1[u], max2[u]);
      }
      h[u][1] = h[u][0] + max1[u];
      if (fa != 0)
        h[u][1] =
            std::max(h[u][1], h[fa][0] + faw[u] + h[u][0] - std::max(h[fa][0], h[fa][1] + faw[u]));
      g[v] = f[v][0] + std::max(h[u][0], h[u][1] + e[i].w);
      if (max1[u] < max2[u]) {
        std::swap(son1[u], son2[u]);
        std::swap(max1[u], max2[u]);
      }
      changeRoot(v, u);
    }
  }
}

int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    add(a, b, c), add(b, a, c);
  }
  dfs(1, 0);
  g[1] = f[1][0];
  changeRoot(1, 0);
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = std::max(ans, g[i]);
  cout << ans << endl;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3647 [APIO2014] 连珠线.in", "r", stdin);
  freopen("P3647 [APIO2014] 连珠线.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
